package cn.lingyangwl.agile.system.service.impl;

import cn.lingyangwl.agile.system.mapper.*;
import cn.lingyangwl.agile.system.model.entity.*;
import cn.lingyangwl.agile.system.model.rqrs.position.*;
import cn.lingyangwl.agile.system.service.*;
import cn.lingyangwl.framework.mybatis.plus.utils.*;
import cn.lingyangwl.framework.tool.core.*;
import cn.lingyangwl.framework.tool.core.exception.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shenguangyang
 */
@Service
public class SysPositionServiceImpl implements SysPositionService {
    @Resource
    private SysPositionMapper sysPositionMapper;

    @Override
    public List<SysPosition> listAll() {
        return sysPositionMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public IPage<SysPosition> pagePosition(PositionQueryReq req) {
        LambdaQueryWrapper<SysPosition> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty( req.getName())) {
            queryWrapper.eq(SysPosition::getName, req.getName());
        }
        return sysPositionMapper.selectPage(PageUtil.to(req), queryWrapper);
    }

    @Override
    public SysPosition getById(Long id) {
        return sysPositionMapper.selectById(id);
    }

    @Override
    public void save(SysPosition sysPosition) {
        if (sysPositionMapper.insert(sysPosition) == 0) {
            throw new BizException("保存失败");
        }
    }

    @Override
    public void updateById(SysPosition sysPosition) {
        sysPositionMapper.updateById(sysPosition);
    }

    @Override
    public void deleteById(Long id) {
        sysPositionMapper.deleteById(id);
    }
}
